<template>
<view class="container">

  <view class="moneyContainer">
    <text>账户{{properties.alias_yue||'余额'}}：</text>
    <text :style="'color:' + setting.platformSetting.defaultColor + ';font-size:2em;'">￥{{moneyAmount}}</text>
  </view>
  <view class="product_page_container2">
        <block v-if="!!Data">
          <view class="moneyitem" v-for="(pay, index) in Data" :key="index">
            
            <view class="eventTypeName">
              <block v-if="pay.eventType == 1">
                <text>账户收入</text>
              </block>
              <block v-else>
                <text>账户支出</text>
              </block>
              <text>当前账户:￥{{pay.afterAmount}}</text>
            </view>
            <view class="eventDerection">
              <view class="left">
                <text class="font_555">{{pay.eventDescription}}</text>
                <text class="time">{{pay.eventTime}}</text>
              </view>
              <view class="right" :style="'color:' + setting.platformSetting.defaultColor">
                <block v-if="pay.eventType == 1">
                  <text class="font_green">￥{{pay.eventAmount}}</text>
                  <text class="font_green font_06">收入</text>
                </block>
                <block v-else>
                  <text class="font_green">￥{{pay.eventAmount}}</text>
                  <text class="font_red font_06">支出</text>
                </block>
              </view>
            </view>
          </view>
        </block>
 
        <block v-else>
          <view class="none">
            <image mode="widthFix" src="https://image1.sansancloud.com/xianhua/2019_12/17/11/9/46_337.jpg?x-oss-process=style/preview_120"></image>
            <text>没有相关记录</text>
          </view>
        </block>
      </view>
</view>
</template>

<script>

export default {
  data() {
    return {
      Data: [],
      moneyAmount: 0,
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
      setting: "",
      properties: ""
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
    this.get_mendian_centerFun();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting,
      properties: getApp().globalData.properties
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.reflesh == 1) {
      this.onPullDownRefresh();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.Data = [];
    this.listPage.page = 1;
    this.getData();
    this.get_mendian_centerFun();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;

    if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
      that.listPage.page++;
      this.getData();
    }
  },
  methods: {
    /* 获取数据 */
    getData: function () {
      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      var getParams = {};
      getParams.page = this.listPage.page;
      var customIndex = getApp().globalData.AddClientUrl("/get_manager_mendian_account_event_admin_mendian_json.html", getParams, 'post');
      var that = this;
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);
          that.listPage.pageSize = res.data.relateObj.pageSize;
          that.listPage.curPage = res.data.relateObj.curPage;
          that.listPage.totalSize = res.data.relateObj.totalSize;
          let dataArr = that.Data;
          dataArr = dataArr.concat(res.data.relateObj.result);

          if (!res.data.relateObj.result || res.data.relateObj.result.length == 0) {
            that.setData({
              Data: null
            });
          } else {
            that.setData({
              Data: dataArr
            });
          }
        }
      });
    },
    get_mendian_centerFun: function (setting) {
      console.log('-------门店--------');
      let params = {};
      var customIndex = getApp().globalData.AddClientUrl("/get_manager_mendian_account_admin_mendian_json.html", params, 'post');
      var that = this; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            let mendianZhanghu = res.data.relateObj; //account 账户余额

            that.setData({
              moneyAmount: mendianZhanghu.account
            });
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>